package com.briup.smartlabs.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.briup.smartlabs.bean.ex.SysLog;
import com.briup.smartlabs.common.utils.Response;
import com.briup.smartlabs.mapper.SysMenuMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags = "实验室信息管理服务")
@RestController
public class SysLabController {
	
	@Autowired
	SysLabController labMapper;
	
	@PostMapping("/lab")
	public Response<String> saveOrUpdateLab(SysLog lab){
		
		return Response.ok("操作成功！");
	}
	@ApiOperation(value = "返回所有实验室信息")
	@GetMapping("/lab/all")
	public Response<List<SysLog>> findAll(){
		List<SysLog> labs = labMapper.selectAll();
		return Response.ok(labs);
	}
	private List<SysLog> selectAll() {
		// TODO Auto-generated method stub
		return null;
	}
	@ApiOperation(value = "分页显示实验室信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "当前页码"),
		@ApiImplicitParam(name = "pageSize",value = "每页显示的数据个数")
	})
	@GetMapping("/lab/by/page")
	public Response<PageInfo<SysLog>> findByPage(
			@RequestParam(defaultValue = "5")int pageSize,
			@RequestParam(defaultValue = "1")int pageNum){
		//表明开始分页，会对接下来代码中遇到的第一条sql语句进行分页查询
		PageHelper.startPage(pageNum, pageSize, true); 
		List<SysLog> labs = labMapper.selectAll();
		PageInfo<SysLog> pages = new PageInfo<>(labs);
		return Response.ok(pages);
	}
	@ApiOperation(value = "按照实验室name删除实验室信息")
	@ApiImplicitParam(name = "name",value = "要删除的实验室的labName")
	@DeleteMapping("/lab/by/name")
	public Response<String> deleteById(Long name){
		if(name==null) {
			return Response.error("请输入要删除的实验室name！");
		}
		((SysMenuMapper) labMapper).deleteByPrimaryKey(name);
		return Response.ok("删除成功！");
	}
}
